#!/usr/bin/env python
# -*- coding: utf-8 -*-#

#-------------------------------------------------------------------------------
# Name:         lab01.py
# Description:  
# Author:       handa
# Date:         2022/4/14
#-------------------------------------------------------------------------------
def falling(n, k):
    """Compute the falling factorial of n to depth k.

    >>> falling(6, 3)  # 6 * 5 * 4
    120
    >>> falling(4, 3)  # 4 * 3 * 2
    24
    >>> falling(4, 1)  # 4
    4
    >>> falling(4, 0)
    1
    """
    "*** YOUR CODE HERE ***"
    if k == 0:
        return 1
    else:
        return n * falling(n - 1, k - 1)

res = falling(4,3)
print(res)



def sum_digits(y):
    """Sum all the digits of y.

    >>> sum_digits(10) # 1 + 0 = 1
    1
    >>> sum_digits(4224) # 4 + 2 + 2 + 4 = 12
    12
    >>> sum_digits(1234567890)
    45
    >>> a = sum_digits(123) # make sure that you are using return rather than print
    >>> a
    6
    """
    "*** YOUR CODE HERE ***"
    sum = 0
    for i in str(y):
        sum += int(i)
    return sum

res = sum_digits(4224)
print(res)
'''
只有string,list,tuple,dict才是可迭代对象，所以把int转成str,但同时要转回int才能进行整型比较运算

'''


def double_eights(n):
    """Return true if n has two eights in a row.
    >>> double_eights(8)
    False
    >>> double_eights(88)
    True
    >>> double_eights(2882)
    True
    >>> double_eights(880088)
    True
    >>> double_eights(12345)
    False
    >>> double_eights(80808080)
    False
    """
    "*** YOUR CODE HERE ***"
    count_eights = 0
    for i in str(n):
        if count_eights >=2:
            return True
        if int(i) == 8:
            count_eights += 1
        else:
            if count_eights > 0:
                count_eights -= 1

    if count_eights >= 2:
        return True
    else:
        return False
'''
这道题主要是结束的边界条件，要连续两个8就可以结束，非连续两个8不符合条件，所以这时你就会写成遇到8，count +=1,非8 count -=1
但是这会导致还没有遇到8时先减成负数，所以边界两件是两个
一个是遇到8才开始count + 或-，二是满足2个就成立返回
'''
def add_in_range(start, stop):
    """
    >>> add_in_range(3, 5)  # .Case 1
    12
    >>> add_in_range(1, 10)  # .Case 2
    55
    """
    "*** YOUR CODE HERE ***"